package com.kiragame.xchat.object;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class MessageContent {
	public enum MsgType {
		TEXT, IMAGE, UPDATE_INFO, SEND_TYPING, SEND_CHAT_VIDEO_REQUEST, SAY_HI_REQUEST
	}

	private Integer fromUserID;
	private String name;
	private String avartar;
	private String content;
	private MsgType msgType;

	public Integer getFromUserID() {
		return fromUserID;
	}

	public void setFromUserID(Integer fromUserID) {
		this.fromUserID = fromUserID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAvartar() {
		return avartar;
	}

	public void setAvartar(String avartar) {
		this.avartar = avartar;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public MsgType getMsgType() {
		return msgType;
	}

	public void setMsgType(MsgType msgType) {
		this.msgType = msgType;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static MessageContent fromJsonToMessageContent(String json) {
		return new JSONDeserializer<MessageContent>().use(null,
				MessageContent.class).deserialize(json);
	}

	public static String toJsonArray(Collection<MessageContent> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<MessageContent> fromJsonArrayToMessageContents(
			String json) {
		return new JSONDeserializer<List<MessageContent>>()
				.use(null, ArrayList.class).use("values", MessageContent.class)
				.deserialize(json);
	}

}
